styleproperty: Make query function take a vfunc
authorBenjamin Otte <otte@redhat.com>
Wed, 11 Jan 2012 01:43:16 +0000 (02:43 +0100)
committerBenjamin Otte <otte@redhat.com>
Wed, 11 Jan 2012 14:48:54 +0000 (15:48 +0100)
This way we can use different methods to query properties and aren't
bound to a GtkStyleProperties object.

gtk/gtkcssshorthandproperty.c
gtk/gtkcssshorthandpropertyimpl.c
gtk/gtkcssshorthandpropertyprivate.h
gtk/gtkcssstyleproperty.c
gtk/gtkstyleproperties.c
gtk/gtkstyleproperty.c
gtk/gtkstylepropertyprivate.h

index 2002cccb2f20750354807adcc5560cc555324321..c47b5305a186081cecebc25110c1684cd955651c 100644 (file)
@@ -75,13 +75,13 @@ _gtk_css_shorthand_property_assign (GtkStyleProperty   *property,
 
 static void
 _gtk_css_shorthand_property_query (GtkStyleProperty   *property,
-                                   GtkStyleProperties *props,
-                                   GtkStateFlags       state,
-                                   GValue             *value)
+                                   GValue             *value,
+                                   GtkStyleQueryFunc   query_func,
+                                   gpointer            query_data)
 {
   GtkCssShorthandProperty *shorthand = GTK_CSS_SHORTHAND_PROPERTY (property);
 
-  shorthand->query (shorthand, value, props, state);
+  shorthand->query (shorthand, value, query_func, query_data);
 }
 
 static gboolean
index 9c088ce84afd3bb0c30c0e4789f4e67de5de5480..aff350a4a477fc883c48d7b17158cb20230c3867 100644 (file)
@@ -537,27 +537,27 @@ unpack_border (GtkCssShorthandProperty *shorthand,
 static void
 pack_border (GtkCssShorthandProperty *shorthand,
              GValue                  *value,
-             GtkStyleProperties      *props,
-             GtkStateFlags            state)
+             GtkStyleQueryFunc        query_func,
+             gpointer                 query_data)
 {
   GtkCssStyleProperty *prop;
   GtkBorder border;
   const GValue *v;
 
   prop = _gtk_css_shorthand_property_get_subproperty (shorthand, 0);
-  v = _gtk_style_properties_peek_property (props, prop, state);
+  v = (* query_func) (_gtk_css_style_property_get_id (prop), query_data);
   if (v)
     border.top = g_value_get_int (v);
   prop = _gtk_css_shorthand_property_get_subproperty (shorthand, 1);
-  v = _gtk_style_properties_peek_property (props, prop, state);
+  v = (* query_func) (_gtk_css_style_property_get_id (prop), query_data);
   if (v)
     border.right = g_value_get_int (v);
   prop = _gtk_css_shorthand_property_get_subproperty (shorthand, 2);
-  v = _gtk_style_properties_peek_property (props, prop, state);
+  v = (* query_func) (_gtk_css_style_property_get_id (prop), query_data);
   if (v)
     border.bottom = g_value_get_int (v);
   prop = _gtk_css_shorthand_property_get_subproperty (shorthand, 3);
-  v = _gtk_style_properties_peek_property (props, prop, state);
+  v = (* query_func) (_gtk_css_style_property_get_id (prop), query_data);
   if (v)
     border.left = g_value_get_int (v);
 
@@ -587,24 +587,21 @@ unpack_border_radius (GtkCssShorthandProperty *shorthand,
 static void
 pack_border_radius (GtkCssShorthandProperty *shorthand,
                     GValue                  *value,
-                    GtkStyleProperties      *props,
-                    GtkStateFlags            state)
+                    GtkStyleQueryFunc        query_func,
+                    gpointer                 query_data)
 {
   GtkCssBorderCornerRadius *top_left;
+  GtkCssStyleProperty *prop;
+  const GValue *v;
 
-  /* NB: We are an int property, so we have to resolve to an int here.
-   * So we just resolve to an int. We pick one and stick to it.
-   * Lesson learned: Don't query border-radius shorthand, query the 
-   * real properties instead. */
-  gtk_style_properties_get (props,
-                            state,
-                            "border-top-left-radius", &top_left,
-                            NULL);
-
-  if (top_left)
-    g_value_set_int (value, top_left->horizontal);
-
-  g_free (top_left);
+  prop = GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("border-top-left-radius"));
+  v = (* query_func) (_gtk_css_style_property_get_id (prop), query_data);
+  if (v)
+    {
+      top_left = g_value_get_boxed (v);
+      if (top_left)
+        g_value_set_int (value, top_left->horizontal);
+    }
 }
 
 static void
@@ -690,35 +687,38 @@ unpack_font_description (GtkCssShorthandProperty *shorthand,
 static void
 pack_font_description (GtkCssShorthandProperty *shorthand,
                        GValue                  *value,
-                       GtkStyleProperties      *props,
-                       GtkStateFlags            state)
+                       GtkStyleQueryFunc        query_func,
+                       gpointer                 query_data)
 {
   PangoFontDescription *description;
-  char **families;
-  PangoStyle style;
-  PangoVariant variant;
-  PangoWeight weight;
-  double size;
-
-  gtk_style_properties_get (props,
-                            state,
-                            "font-family", &families,
-                            "font-style", &style,
-                            "font-variant", &variant,
-                            "font-weight", &weight,
-                            "font-size", &size,
-                            NULL);
+  const GValue *v;
 
   description = pango_font_description_new ();
-  /* xxx: Can we set all the families here somehow? */
-  if (families)
-    pango_font_description_set_family (description, families[0]);
-  pango_font_description_set_size (description, round (size * PANGO_SCALE));
-  pango_font_description_set_style (description, style);
-  pango_font_description_set_variant (description, variant);
-  pango_font_description_set_weight (description, weight);
 
-  g_strfreev (families);
+  v = (* query_func) (_gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("font-family"))), query_data);
+  if (v)
+    {
+      const char **families = g_value_get_boxed (v);
+      /* xxx: Can we set all the families here somehow? */
+      if (families)
+        pango_font_description_set_family (description, families[0]);
+    }
+
+  v = (* query_func) (_gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("font-size"))), query_data);
+  if (v)
+    pango_font_description_set_size (description, round (g_value_get_double (v) * PANGO_SCALE));
+
+  v = (* query_func) (_gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("font-style"))), query_data);
+  if (v)
+    pango_font_description_set_style (description, g_value_get_enum (v));
+
+  v = (* query_func) (_gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("font-variant"))), query_data);
+  if (v)
+    pango_font_description_set_variant (description, g_value_get_enum (v));
+
+  v = (* query_func) (_gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("font-weight"))), query_data);
+  if (v)
+    pango_font_description_set_weight (description, g_value_get_enum (v));
 
   g_value_take_boxed (value, description);
 }
@@ -744,8 +744,8 @@ unpack_to_everything (GtkCssShorthandProperty *shorthand,
 static void
 pack_first_element (GtkCssShorthandProperty *shorthand,
                     GValue                  *value,
-                    GtkStyleProperties      *props,
-                    GtkStateFlags            state)
+                    GtkStyleQueryFunc        query_func,
+                    gpointer                 query_data)
 {
   GtkCssStyleProperty *prop;
   const GValue *v;
@@ -759,7 +759,7 @@ pack_first_element (GtkCssShorthandProperty *shorthand,
   for (i = 0; i < _gtk_css_shorthand_property_get_n_subproperties (shorthand); i++)
     {
       prop = _gtk_css_shorthand_property_get_subproperty (shorthand, 0);
-      v = _gtk_style_properties_peek_property (props, prop, state);
+      v = (* query_func) (_gtk_css_style_property_get_id (prop), query_data);
       if (v)
         {
           g_value_copy (v, value);
index 110fdc6ee929cc313a7da2c3b900057ed7373d2b..a8bfaaeef08031ff77123d417a04e8a6e453c5e2 100644 (file)
@@ -49,8 +49,8 @@ typedef void                  (* GtkCssShorthandPropertyAssignFunc)     (GtkCssS
                                                                          const GValue            *value);
 typedef void                  (* GtkCssShorthandPropertyQueryFunc)      (GtkCssShorthandProperty *shorthand,
                                                                          GValue                  *value,
-                                                                         GtkStyleProperties      *props,
-                                                                         GtkStateFlags            state);
+                                                                         GtkStyleQueryFunc        query_func,
+                                                                         gpointer                 query_data);
 
 struct _GtkCssShorthandProperty
 {
index d547ce31f3f6a5953906222c5e3e59e3ec2ab657..2fb28d9f8364b2b59be12d6143c79313e61facfa 100644 (file)
@@ -117,13 +117,13 @@ _gtk_css_style_property_assign (GtkStyleProperty   *property,
 
 static void
 _gtk_css_style_property_query (GtkStyleProperty   *property,
-                               GtkStyleProperties *props,
-                               GtkStateFlags       state,
-                               GValue             *value)
+                               GValue             *value,
+                               GtkStyleQueryFunc   query_func,
+                               gpointer            query_data)
 {
   const GValue *val;
   
-  val = _gtk_style_properties_peek_property (props, GTK_CSS_STYLE_PROPERTY (property), state);
+  val = (* query_func) (GTK_CSS_STYLE_PROPERTY (property)->id, query_data);
   if (val)
     {
       /* Somebody make this a vfunc */
index 981c9cd30ef3ada9fe19368c499f1e1231e78ba9..ecb79f52d4dbbf516d0d51e3e4b5e9bde909bc9f 100644 (file)
@@ -605,6 +605,22 @@ _gtk_style_properties_peek_property (GtkStyleProperties  *props,
   return property_data_match_state (prop, state);
 }
 
+typedef struct {
+  GtkStyleProperties *props;
+  GtkStateFlags       state;
+} StyleQueryData;
+
+static const GValue *
+style_query_func (guint    id,
+                  gpointer data)
+{
+  StyleQueryData *query = data;
+
+  return _gtk_style_properties_peek_property (query->props,
+                                              _gtk_css_style_property_lookup_by_id (id),
+                                              query->state);
+}
+
 /**
  * gtk_style_properties_get_property:
  * @props: a #GtkStyleProperties
@@ -625,6 +641,7 @@ gtk_style_properties_get_property (GtkStyleProperties *props,
                                    GtkStateFlags       state,
                                    GValue             *value)
 {
+  StyleQueryData query = { props, state };
   GtkStyleProperty *node;
 
   g_return_val_if_fail (GTK_IS_STYLE_PROPERTIES (props), FALSE);
@@ -643,7 +660,10 @@ gtk_style_properties_get_property (GtkStyleProperties *props,
       return FALSE;
     }
 
-  _gtk_style_property_query (node, props, state, value);
+  _gtk_style_property_query (node,
+                             value,
+                             style_query_func,
+                             &query);
   return TRUE;
 }
 
index be86c97e5aef045c20a738d8fd90ce11e0ae67a9..928bf58ed0fa576525047b070ebe5d43b6baaf88 100644 (file)
@@ -198,32 +198,32 @@ _gtk_style_property_assign (GtkStyleProperty   *property,
 /**
  * _gtk_style_property_query:
  * @property: the property
- * @props: The properties to query
- * @state: The state to query
  * @value: (out): an uninitialized #GValue to be filled with the
  *   contents of the lookup
+ * @query_func: The function to use to query properties
+ * @query_data: The data to pass to @query_func
  *
  * This function is called by gtk_style_properties_get() and in
  * turn gtk_style_context_get() and similar functions to get the
  * value to return to code using old APIs.
  **/
 void
-_gtk_style_property_query (GtkStyleProperty        *property,
-                           GtkStyleProperties      *props,
-                           GtkStateFlags            state,
-                           GValue                  *value)
+_gtk_style_property_query (GtkStyleProperty  *property,
+                           GValue            *value,
+                           GtkStyleQueryFunc  query_func,
+                           gpointer           query_data)
 {
   GtkStylePropertyClass *klass;
 
-  g_return_if_fail (property != NULL);
-  g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
+  g_return_if_fail (GTK_IS_STYLE_PROPERTY (property));
   g_return_if_fail (value != NULL);
+  g_return_if_fail (query_func != NULL);
 
   klass = GTK_STYLE_PROPERTY_GET_CLASS (property);
 
   g_value_init (value, property->value_type);
 
-  klass->query (property, props, state, value);
+  klass->query (property, value, query_func, query_data);
 }
 
 void
index 58aaf2abc9694ff621e4dbab791f3aa70b950659..5ba4d85c20c47ced1b50777c4013e79697fafdc0 100644 (file)
@@ -39,6 +39,9 @@ typedef enum {
   GTK_STYLE_PROPERTY_INHERIT = (1 << 0)
 } GtkStylePropertyFlags;
 
+typedef const GValue *   (* GtkStyleQueryFunc)             (guint                   id,
+                                                            gpointer                data);
+
 struct _GtkStyleProperty
 {
   GObject parent;
@@ -56,9 +59,9 @@ struct _GtkStylePropertyClass
                                                             GtkStateFlags           state,
                                                             const GValue           *value);
   void              (* query)                              (GtkStyleProperty       *property,
-                                                            GtkStyleProperties     *props,
-                                                            GtkStateFlags           state,
-                                                            GValue                 *value);
+                                                            GValue                 *value,
+                                                            GtkStyleQueryFunc       query_func,
+                                                            gpointer                query_data);
   gboolean          (* parse_value)                        (GtkStyleProperty *      property,
                                                             GValue                 *value,
                                                             GtkCssParser           *parser,
@@ -82,9 +85,9 @@ gboolean                 _gtk_style_property_parse_value   (GtkStyleProperty *
 
 GType                    _gtk_style_property_get_value_type(GtkStyleProperty *      property);
 void                     _gtk_style_property_query         (GtkStyleProperty *      property,
-                                                            GtkStyleProperties     *props,
-                                                            GtkStateFlags           state,
-                                                            GValue                 *value);
+                                                            GValue                 *value,
+                                                            GtkStyleQueryFunc       query_func,
+                                                            gpointer                query_data);
 void                     _gtk_style_property_assign        (GtkStyleProperty       *property,
                                                             GtkStyleProperties     *props,
                                                             GtkStateFlags           state,